package com.hucheng.rest.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hucheng.activity.query.ExchangeQuery;
import com.hucheng.activity.service.ExchangeService;
import com.hucheng.activity.vo.ExchangePrizeVO;
import com.hucheng.activity.vo.ExchangeVO;
import com.hucheng.common.exception.EduException;
import com.hucheng.common.page.CommonPager;
import com.hucheng.common.page.PageParameter;
import com.hucheng.common.response.ServiceCoreVO;
import com.hucheng.common.utils.ValidatorUtils;
import com.hucheng.rest.base.BaseAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-15
 * @Description: 兑换活动
 **/
@Slf4j
@Controller("exchangeAction")
public class ExchangeAction extends BaseAction {

    @Reference
    private ExchangeService exchangeService;

    /**
     * 兑换活动列表
     *
     * @return
     * @throws EduException
     */
    public ServiceCoreVO listV100() throws EduException {

        String currentPage = getRequestContentValue("currentPage");
        String pageSize = getRequestContentValue("pageSize");

        PageParameter pageParameter = new PageParameter();
        if (currentPage != null && !currentPage.equals("null") &&
                pageSize != null && !pageSize.equals("null")) {
            pageParameter = new PageParameter(Integer.parseInt(currentPage), Integer.parseInt(pageSize));
        }

        ExchangeQuery exchangeQuery = new ExchangeQuery();
        exchangeQuery.setPageParameter(pageParameter);
        CommonPager<ExchangeVO> commonPager = exchangeService.list(exchangeQuery);

        return response(commonPager);
    }
    /**
     * 兑换
     *
     * @return
     * @throws EduException
     */
    public ServiceCoreVO exchangeV100() throws EduException {

        String exchangeConfigId = getRequestContentValue("exchange_config_id");
        String exchangeNo = getRequestContentValue("exchange_no");

        if(ValidatorUtils.isEmpty(exchangeConfigId)){
            throw new EduException(160004);
        }

        if(ValidatorUtils.isEmpty(exchangeNo)){
            throw new EduException(160005);
        }

        ExchangePrizeVO exchangePrizeVO = exchangeService.exchange(userId,Integer.parseInt(exchangeConfigId),Integer.parseInt(exchangeNo));

        return response(exchangePrizeVO);
    }


}
